package com.dms.modules.user.controller;

import com.dms.common.api.ApiResponse;
import com.dms.common.security.SecurityUtils;
import com.dms.modules.merchant.service.MerchantService;
import com.dms.modules.user.dto.MerchantApplyDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/v1/user/merchant")
@Api(tags = "用户商家接口")
@PreAuthorize("isAuthenticated()")
@Validated
public class UserMerchantController {

    @Autowired
    private MerchantService merchantService;

    @PostMapping("/apply/merchant")
    @ApiOperation(value = "申请成为商家", notes = "用户申请成为商家，需要提供店铺相关信息")
    @PreAuthorize("hasRole('USER')")
    public ApiResponse<Long> applyMerchant(@RequestBody @Validated MerchantApplyDTO applyDTO) {
        log.info("用户申请成为商家: {}", applyDTO.getShopName());
        Long userId = SecurityUtils.getCurrentUserId();
        Long merchantId = merchantService.applyMerchant(userId, applyDTO);
        return ApiResponse.success(merchantId);
    }
} 